package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2022-12-05
 * Time: 15:47
 */
public class BorrowedOperation implements IOperation{
    @Override
    public void Work(BookList bookList) {
        System.out.println("借出图书！");
        System.out.println("请输入要借出书的名字：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int curSize = bookList.getUseSize();
        int index = -1;

        for (int i = 0; i < curSize; i++) {
            Book book = bookList.getBooks(i);
            String bookName = book.getName();
            if (bookName.equals(name) && !book.isBorrowed()) {
                index = i;
                break;
            }
        }

        if (index == -1) {
            System.out.println("要借出的书不存在或已被借出！");
            return;
        }
        Book book = bookList.getBooks(index);
        book.setBorrowed(true);
        System.out.println("借出完毕！");
    }
}
